def show_menu():
    print('*' * 50)
    print('欢迎使用【名片管理系统】v1.0')
    print('')
    print("1.新增名片!")
    print('2.显示全部!')
    print('3.查询名片!')
    print('')
    print('0:退出系统')
    print('*' * 50)


card_list = []


def new_card():
    print('-' * 50)
    name = input('请输入姓名:')
    phone = input('请输入手机号:')
    qq_number = input('请输入qq号码:')
    email = input('请输入邮箱账号:')
    card_list.append({"name": name, "phone": phone, "qq_number": qq_number, "email": email})


def show_table(list):
    for name in ['姓名', '电话', 'QQ', '邮箱']:
        print(name, end="\t\t")
    print('')
    print('-' * 50)
    for item in list:
        for item_item in item:
            print(item[item_item], end="\t\t")
        print('')
        print('+' * 50)


def show_all():
    print('-' * 50)
    if len(card_list) == 0:
        print('当前没有任何记录,请先添加记录!')
    else:
        show_table(card_list)
    print('-' * 50)


def search_card():
    print('-' * 50)
    name = input('请输入需要查询的姓名:')
    for item in card_list:
        if item['name'] == name:
            show_table([item])
            caozuo = input('请选择要执行的操作: 修改(1)/删除(2)/返回(0)')
            if caozuo == '1':
                update_find_name(item)
            elif caozuo == '2':
                del_find_name(item)
            break
    else:
        print('查无此人!')


def del_find_name(item):
    card_list.remove(item)


def update_find_name(item):
    """
    与JS有大同小异之处(内存地址)
    :param item: 查找到的字典
    """
    item['name'] = input_info_value(item['name'], '姓名:')
    item['phone'] = input_info_value(item['phone'], '电话:')
    item['qq_number'] = input_info_value(item['qq_number'], 'QQ:')
    item['email'] = input_info_value(item['email'], '邮箱:')


def input_info_value(def_val, message):
    """
    :param def_val: 字典中原有的值
    :param message: 提示信息
    :return: 如果用户输入了内容,返回输入的内容,反之,返回原有的值
    """
    result_value = input(message + "[不修改就回车]")
    if len(result_value) > 0:
        return result_value
    else:
        return def_val
